package br.ucb.sacop.activities;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
import br.ucb.sacop.R;

public class MenuActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu_principal);

		ImageButton btnPesquisarBibliografia = (ImageButton) findViewById(R.id.pesquisar_bibliografia);
		btnPesquisarBibliografia.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Uri uri = Uri
						.parse("http://marakatu.ucb.br/pergamum/biblioteca/index.php");
				Intent intent = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(intent);
			}
		});
		
		ImageButton btBuscarTurmas = (ImageButton) findViewById(R.id.adicionarTurma);
		btBuscarTurmas.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Bundle extras = getIntent().getExtras();
				int alunoId = -1;
				if(extras != null)
					alunoId = extras.getInt("alunoId");
				if(alunoId != -1){
					Intent intent = new Intent();
					intent.setClass(MenuActivity.this, TurmaActivity.class);
					intent.putExtra("alunoId", alunoId);
					startActivity(intent);
				}else{
					gerarToast("Falha ao buscar turmas!");
				}
			}
		});
		
		ImageButton btCadastrarNotas = (ImageButton) findViewById(R.id.cadastrarNotas);
		btCadastrarNotas.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Bundle extras = getIntent().getExtras();
				int alunoId = -1;
				if(extras != null)
					alunoId = extras.getInt("alunoId");
				if(alunoId != -1){
					Intent intent = new Intent();
					intent.setClass(MenuActivity.this, CadastrarNotaActivity.class);
					intent.putExtra("alunoId", alunoId);
					startActivity(intent);
				}else{
					gerarToast("Falha ao buscar turmas!");
				}
			}
		});
		
		ImageButton btVerMsg = (ImageButton) findViewById(R.id.ver_mensagem);
		btVerMsg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Bundle extras = getIntent().getExtras();
				int alunoId = -1;
				if(extras != null)
					alunoId = extras.getInt("alunoId");
				if(alunoId != -1){
					Intent intent = new Intent();
					intent.setClass(MenuActivity.this, SelecionaMensagemActivity.class);
					intent.putExtra("alunoId", alunoId);
					startActivity(intent);
				}else{
					gerarToast("Falha ao recuperar registros!");
				}
			}
		});
		
		ImageButton btVerPlano = (ImageButton) findViewById(R.id.verPlano);
		btVerPlano.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Bundle extras = getIntent().getExtras();
				int alunoId = -1;
				if(extras != null)
					alunoId = extras.getInt("alunoId");
				if(alunoId != -1){
					Intent intent = new Intent();
					intent.setClass(MenuActivity.this, SelecionaPlanoActivity.class);
					intent.putExtra("alunoId", alunoId);
					startActivity(intent);
				}else{
					gerarToast("Falha ao recuperar registros!");
				}
			}
		});
	}
	private void gerarToast(CharSequence message) {
		int duration = Toast.LENGTH_LONG;
		Toast toast = Toast
				.makeText(getApplicationContext(), message, duration);
		toast.show();
	}
}
